// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <iostream>

#include <pollux/vector/flat_vector.h>
#include <pollux/vector/fuzzer/generator_spec.h>
#include <tests/vector/fuzzer/examples/Utils.h>

using namespace kumo::pollux;
using namespace generator_spec_maker;
using namespace generator_spec_examples;

int main() {
  // This example shows how to use our GeneratorSpec class to generate vectors
  // of arrays with user defined distributions.

  constexpr int sampleSize = 100;
  constexpr int32_t lo = 100, hi = 1000;
  constexpr double mu = 5.0, sigma = 2.0;
  constexpr double nullProbability = 0.38;

  auto normal = std::normal_distribution<double>(mu, sigma);
  auto uniform = std::uniform_int_distribution<int32_t>(lo, hi);

  FuzzerGenerator rng;
  memory::MemoryManager::initialize({});
  auto pool = memory::memoryManager()->addLeafPool();

  GeneratorSpecPtr randomArray =
      RANDOM_ARRAY(RANDOM_DOUBLE(normal, nullProbability), uniform);

  VectorPtr vector = randomArray->generateData(rng, pool.get(), sampleSize);
  ArrayVector* array_vector = vector->as<ArrayVector>();
  VectorPtr elements = array_vector->elements();

  std::cout
      << "Underlying elements of ArrayVector generated from normal distribution:\n"
      << plotVector(elements->as_flat_vector<double>()) << "\n";

  return 0;
}
